package com.sen.common.utils;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;

/**
* 字符串的连接工具类.
* 
* @author sen
*/
public final class Joiner {

	private final String separator;

	private Joiner(String separator) {
		this.separator = separator;
	}
	
	public static Joiner with(char separator) {
		return with(String.valueOf(separator));
	}
	
	public static Joiner with(String separator) {
		return new Joiner(separator);
	}

	public String join(String... values) {
		if (ArrayUtils.isEmpty(values)) {
			return StringUtils.EMPTY;
		}
		return StringUtils.join(values, separator);
	}

	public String join(boolean isSuccessful, String... values) {
		if (ArrayUtils.isEmpty(values)) {
			return String.valueOf(isSuccessful);
		}
		int len = values.length + 1;
		String[] joined = new String[len];
		int index = 0;
		joined[index] = String.valueOf(isSuccessful);
		for (String value : values) {
			joined[++index] = value;
		}
		return join(joined);
	}
}
